﻿using Model.Admin;
using Services.WXProjectAdmin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WeiXinpProAdmin.Controllers
{
    public class UserInfoController : AdminBaseController
    {
        AdminUserInfoServices m_AdminUserInfoServices;
        public UserInfoController( AdminUserInfoServices mAdminUserInfoServices)
       {           
            m_AdminUserInfoServices = mAdminUserInfoServices;
        }
        // GET: UserInfo
        public ActionResult Index()
        {
            return View();
        }
       
        public ActionResult EditUserInfo()
        {      
            return View(this.CurrentUser);
        }

        public JsonResult UserInfoEdit(FormCollection collection)
        {
            var jsonData = new Object();
            string result = string.Empty;
            bool success = false;
            string Id = collection["ID"];
            AdminUser user = new AdminUser();
            if (!string.IsNullOrEmpty(Id))
            {
                user = m_AdminUserInfoServices.GetById(Id);
            }        
            user.Email = collection["Email"];
            user.Mobile = collection["Mobile"];
            success = m_AdminUserInfoServices.EditAdminUser(user, CurrentUser.UserID.ToString());
            result = (success) ? "编辑用户成功！" : "编辑用户失败！";
            jsonData = new { Success = success, Data = result };
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }
    }
}